/*
ID: icerupt1
PROG: shopping
LANG: C++11
*/

/* solution
 *
 * good maybe. dp. 难点在于实现，本来想动态维度的，发现不好抽象，
 * 我太弱了。。就固定维度，好写点。
 *
*/
#include <fstream>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <array>

std::ifstream fin {"shopping.in" };
std::ofstream fout{"shopping.out"};

struct product { int key; int num; int price; };

struct special_offer
{
	std::vector<product> offer;
	int reduced_price;
};

int const maxn = 6;
int f[maxn][maxn][maxn][maxn][maxn];

std::unordered_map<int, int> key;
std::vector<special_offer> sos;
std::vector<product> buy(maxn);
int s, n, product_num;

bool check(int s, int t, std::array<int, 5> const & num)
{
	for (int i = 0; i < maxn; i++)
		if (sos[s].offer[i].num * t > num[i]) return false;
	return true;
}

int main()
{
	fin >> s;
	sos.resize(s);
	for (int i = 0, num; i < s; i++) {
		fin >> num;
		sos[i].offer.resize(maxn);
		for (int j = 0, tmp; j < num; j++) {
			fin >> tmp;
			if (key.find(tmp) == key.end())
				key[tmp] = product_num++;
			fin >> sos[i].offer[key[tmp]].num;
			sos[i].offer[key[tmp]].key = key[tmp];
		}
		fin >> sos[i].reduced_price;
	}

	fin >> n;
	for (int i = 0, tmp; i < n; i++) {
		fin >> tmp;
		if (key.find(tmp) == key.end())
			key[tmp] = product_num++;
		buy[key[tmp]].key = key[tmp];
		fin >> buy[key[tmp]].num >> buy[key[tmp]].price;
	}

	for (auto i0 = 0; i0 < maxn; i0++)
	for (auto i1 = 0; i1 < maxn; i1++)
	for (auto i2 = 0; i2 < maxn; i2++)
	for (auto i3 = 0; i3 < maxn; i3++)
	for (auto i4 = 0; i4 < maxn; i4++) {
		f[i0][i1][i2][i3][i4] = buy[0].price * i0 + buy[1].price * i1
				+ buy[2].price * i2 + buy[3].price * i3
					+ buy[4].price * i4;
	}

	for (auto i = 0; i < s; i++) {
		for (auto i0 = 0; i0 < maxn; i0++)
		for (auto i1 = 0; i1 < maxn; i1++)
		for (auto i2 = 0; i2 < maxn; i2++)
		for (auto i3 = 0; i3 < maxn; i3++)
		for (auto i4 = 0; i4 < maxn; i4++) {
			if (check(i, 1, {{i0, i1, i2, i3, i4}})) {
				f[i0][i1][i2][i3][i4] = std::min(f[i0][i1][i2][i3][i4],
						f[i0 - sos[i].offer[0].num][i1 - sos[i].offer[1].num]
							[i2 - sos[i].offer[2].num][i3 - sos[i].offer[3].num]
								[i4 - sos[i].offer[4].num] + sos[i].reduced_price);
			}
		}
	}
	std::cout << f[buy[0].num][buy[1].num][buy[2].num][buy[3].num][buy[4].num] << '\n';
	fout << f[buy[0].num][buy[1].num][buy[2].num][buy[3].num][buy[4].num] << '\n';
}

